﻿using DocumentFormat.OpenXml.Bibliography;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RouteConvertTool
{
    internal class Program
    {


        static void test_ConvertLatLonToUtm()
        {
            //    // 北京坐标示例
            double lat = 29.942859645453215;
            double lon = 114.4979476993271;
            lon = 117.3114829515;
            lat = 36.7086888972;

            UtmConverter.ConvertLatLonToUtm(lat, lon, out double easting, out double northing, out int zone);

            Console.WriteLine($"UTM Zone: {zone}");
            Console.WriteLine($"Easting x: {easting}");
            Console.WriteLine($"Northing y: {northing}");
            Console.ReadKey();
        }

        static void test2() 
        {
            string csvFile = "E:\\2025年工作\\山东仿线02月\\航线裁剪\\航线.csv";

            string[] lines = File.ReadAllLines(csvFile);


            List<WaypointX> xs = WaypointCsvParser.ParseCsv(csvFile);
            foreach (var wp in xs)
            {
                wp.LineName = "测试线路";
                wp.VoltageLevel = "10kV";
                wp.TowerNumber = "#42";
                wp.TowerType = "直线塔";
                wp.ComponentLongitude = wp.Longitude;
                wp.ComponentLatitude = wp.Latitude;
                wp.ComponentAltitude = wp.AbsoluteHeight;

                double lat = wp.Latitude.Value;
                double lon = wp.Longitude.Value;
                UtmConverter.ConvertLatLonToUtm(lat, lon, out double easting, out double northing, out int zone);
                wp.X = easting;
                wp.Y = northing;
                wp.ComponentX = northing;
                wp.ComponentY = northing;


                Console.WriteLine($"序号: {wp.SerialNo}, 部件标签: {wp.ComponentTag}, 经度: {wp.Longitude}, 纬度: {wp.Latitude}, 绝对高度: {wp.AbsoluteHeight}");
            }
            ExcelHelper.ExportToExcel(xs, "waypoints2.xlsx");
            return;

        }


        /// <summary>
        /// excel 转 kml
        /// </summary>
        static void test_excel_2_kml()
        {
            string file = "E:\\2025年工作\\山东仿线02月\\500kv龙韶线#42-43_jxh.xlsx";
            file = "E:\\2025年工作\\山东仿线02月\\航线裁剪\\测试线#42_jxh.xlsx";
            //file = "D:\\code_cpp\\demos\\RouteConvertTool\\RouteConvertTool\\bin\\Debug\\waypoints.xlsx";
            //file = "D:\\code_cpp\\demos\\RouteConvertTool\\RouteConvertTool\\bin\\Debug\\waypoints2.xlsx";
            List<Waypoint> waypoints = ExcelParser.ParseExcelToWaypoints(file);

            // 打印结果以验证
            foreach (var waypoint in waypoints)
            {
                Console.WriteLine($" {waypoint.No} Route Name: {waypoint.routeName}, Tower No: {waypoint.towerNo}, Latitude: {waypoint.Coordinates.Latitude}, Longitude: {waypoint.Coordinates.Longitude}, Altitude: {waypoint.Coordinates.Altitude}, Heading: {waypoint.Heading}, Component Type: {waypoint.ComponentType}");
            }

            //foreach (var waypoint in waypoints)
            //{                
            //    Console.WriteLine($" {waypoint.No} , Latitude: {waypoint.ComponentLat}, Longitude: {waypoint.ComponentLon}, Altitude: {waypoint.ComponentAlt}");
            //}

            KmlGenerator.GenerateWaypointKML("output1.kml", waypoints);
        }

        static void Main(string[] args)
        {

            test_excel_2_kml();
            Console.ReadKey();
        }


        private static void test_1() {

            // 创建航点列表
            List<WaypointX> waypointXs = CreateWaypoints();

            ExcelHelper.ExportToExcel(waypointXs, "waypoints.xlsx");

            Console.WriteLine("done!!!");
            Console.ReadKey();
        }

        // 创建航点数据
        private static List<WaypointX> CreateWaypoints()
        {
            // 示例数据（按需替换为实际数据）
            return new List<WaypointX>
        {
            // 航点 1
            new WaypointX
            {
                SerialNo = 1,
                LineName = "500kv龙韶线#42-43",
                VoltageLevel = "500kV",
                TowerNumber = "#42",
                TowerType = "直线塔",
                Phase = "",
                StrainSide = "",
                ComponentTag = "转弯点",
                RelativePosition = "",
                Notes = "",
                GimbalPitchAngle = -45.0,
                YawAngle = -97.8318619175,
                Longitude = 117.3114829515,
                Latitude = 36.7086888972,
                AbsoluteHeight = 154.5090158715,
                X = 527819.936584,
                Y = 4062602.278812,
                ComponentLongitude = 117.3115279912,
                ComponentLatitude = 36.7087518832,
                ComponentAltitude = 152.5090158715,
                ComponentX = 527823.936584,
                ComponentY = 4062609.278812,
                StartHeight = 152.509016
            },
            // 航点 2（按需添加更多航点）
            new WaypointX
            {
                SerialNo = 2,
                LineName = "500kv龙韶线#42-43",
                VoltageLevel = "500kV",
                TowerNumber = "#42",
                TowerType = "直线塔",
                Phase = "",
                StrainSide = "",
                ComponentTag = "转弯点",
                RelativePosition = "",
                Notes = "",
                GimbalPitchAngle = -45.0,
                YawAngle = -97.8318619175,
                Longitude = 117.3114829515,
                Latitude = 36.7086888972,
                AbsoluteHeight = 139.5090158715,
                X = 527819.936584,
                Y = 4062602.278812,
                ComponentLongitude = 117.3115279912,
                ComponentLatitude = 36.7087518832,
                ComponentAltitude = 137.5090158715,
                ComponentX = 527823.936584,
                ComponentY = 4062609.278812,
                StartHeight = 137.509016
            }
        };
        }
    }
}
